home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
MNetsrc.hqx
/
Mac TCP_IP Source v.33
/
Other Files.SIT
/
sys5unix.c
< prev
next >
Wrap
Text File
|
1989-01-13
|
4KB
|
269 lines
/*
FILE: unix.c
Routines: This file contains the following routines:
eihalt()
kbread()
clksec()
tmpfile()
restore()
stxrdy()
disable()
memstat()
filedir()
Written by Mikel Matthews, N9DVG
SYS5 stuff added by Jere Sandidge, K4FUM
*/
#include <stdio.h>
#include <signal.h>
#include <termio.h>
#include "global.h"
#include "cmdparse.h"
#include "iface.h"
#include <sys/types.h>
#include <sys/dir.h>
#include <time.h>
#include "smtp.h"
#include "unix.h"
unsigned nasy;
int asy_attach();
extern struct cmds attab[];
extern struct termio savecon;
eihalt()
{
}
kbread()
{
unsigned char c;
if (read(fileno(stdin), &c, 1) <= 0)
return (-1);
return ((int) c);
}
clksec()
{
long tim;
(void)time(&tim);
return ((int) tim);
}
restore()
{}
stxrdy()
{return(1);}
disable()
{}
memstat()
{
return(0);
}
/* wildcard filename lookup */
filedir (name, times, ret_str)
char *name;
int times;
char *ret_str;
{
static FILE *dirp = NULL;
struct direct dent;
struct direct *dp = &dent;
char fn[DIRSIZ+1], ext[DIRSIZ+1];
char *ptr;
char *cp;
char tmp1[DIRSIZ+1];
char tmp2[DIRSIZ+1];
char *index(), *rindex();
extern char mailqdir[];
/*
* Make sure that the NULL is there incase we don't find anything
*/
ret_str[0] = NULL;
if(name == NULLCHAR || name[0] == '\0')
name = "*.*";
if (cp = rindex(name, '/')) {
cp++;
if (ptr = index(cp, '.'))
*ptr++ = NULL;
strncpy(fn, cp, DIRSIZ-1);
fn[DIRSIZ-1] = NULL;
strncpy(ext, ptr, DIRSIZ-1);
ext[DIRSIZ] = NULL;
}
else
return;
if (dirp == NULL) {
if ( (dirp = fopen(mailqdir, "r")) == NULL ) {
printf("Could not open mail queue (%s)\n",mailqdir);
return;
}
}
if (times == 0) {
rewind(dirp);
/* skip over dot and dot dot */
if (fread((char *)dp, sizeof(dent), 1, dirp) != 1) {
printf("Could not read mail queue (%s)\n", mailqdir);
fclose(dirp);
dirp = NULL;
return;
}
if (fread((char *)dp, sizeof(dent), 1, dirp) != 1) {
printf("Could not read mail queue (%s)\n", mailqdir);
fclose(dirp);
dirp = NULL;
return;
}
}
while (fread((char *)dp, sizeof(dent), 1, dirp) == 1) {
strncpy(tmp1, dp->d_name, DIRSIZ); /* need NULL term */
tmp1[DIRSIZ] = NULL;
if ((ptr = index(tmp1, '.')) == NULL)
continue;
strcpy(tmp2, tmp1);
*ptr++ = NULL;
if ((strcmp(tmp1, fn) != 0) && (fn[0] != '*'))
continue;
if ((strcmp(ptr, ext) != 0) && (ext[0] != '*'))
continue;
strcpy(ret_str, tmp2);
break;
}
}
/* checks the time then ticks and updates ISS */
static int clkval = 0;
void
check_time()
{
int32 iss();
if(clkval != clksec()){
clkval = clksec();
tick();
(void)iss();
}
}
getds()
{
return (0);
}
audit(){}
doshell(argc, argv)
char **argv;
{
register int pid, pid1, i, (*savi)();
int rc;
char str[128];
struct termio stty;
ioctl(0, TCGETA, &stty);
ioctl(0, TCSETA, &savecon);
str[0] = '\0';
for (i = 1; i < argc; i++) {
strcat(str, argv[i]);
strcat(str, " ");
}
if ((pid = fork()) == 0) {
if (argc > 1)
(void)execl("/bin/sh", "sh", "-c", str, 0);
else
(void)execl("/bin/sh", "/bin/sh", (char *)0,(char *)0,0);
}
savi = signal(SIGINT, SIG_IGN);
while ((pid1 = wait(&rc)) != pid && pid1 != -1)
;
signal(SIGINT, savi);
ioctl(0, TCSETA, &stty);
return (rc);
}
dodir(argc, argv)
char **argv;
{
register int pid, pid1, i, (*savi)();
int rc;
char str[128];
strcpy(str, "ls -l ");
for (i = 1; i < argc; i++) {
strcat(str, argv[i]);
strcat(str, " ");
}
if ((pid = fork()) == 0)
system(str);
savi = signal(SIGINT, SIG_IGN);
while ((pid1 = wait(&rc)) != pid && pid1 != -1)
;
signal(SIGINT, savi);
return (rc);
}
rename(s1, s2)
register char *s1, *s2;
{
char tmp[256];
(void)sprintf(tmp, "mv %s %s", s1, s2);
(void)system(tmp);
}
docd(argc, argv)
char **argv;
{
char tmp[128];
char *getcwd();
if (argc > 1)
if (chdir(argv[1]))
return (-1);
if (getcwd(tmp, 128) == NULL)
return (-1);
puts(tmp);
return (0);
}
ether_dump()
{
}
mkdir(s, m)
register char *s;
register int m;
{
char tmp[128];
sprintf(tmp, "mkdir %d %s", m, s);
if (system(tmp))
return (-1);
return (0);
}
rmdir(s)
register char *s;
{
char tmp[128];
sprintf(tmp, "rmdir %s", s);
if (system(tmp))
return (-1);
return (0);
}